package com.example.demo.controller;


import com.example.demo.common.Result;
import com.example.demo.common.anno.UserRole;
import com.example.demo.entity.SysQuestionAnswer;
import com.example.demo.service.SysQuestionAnswerService;
import com.example.demo.utils.enu.UserRoleEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ld&zjw
 * @since 2024-01-27
 */
@RestController
@RequestMapping("/news")
public class SysQuestionAnswerController {

    @Autowired
    SysQuestionAnswerService sysQuestionAnswerService;

    @PostMapping
    public Result<?> save(@RequestBody SysQuestionAnswer news) {
        return Result.success(sysQuestionAnswerService.save(news));
    }

    @PutMapping
    public Result<?> update(@RequestBody SysQuestionAnswer news) {
        return Result.success(sysQuestionAnswerService.update(news));
    }

    @DeleteMapping("/{id}")
    public Result<?> update(@PathVariable Long id) {
        return Result.success(sysQuestionAnswerService.update(id));
    }

    @GetMapping("/{id}")
    public Result<?> getById(@PathVariable Long id) {
        return Result.success(sysQuestionAnswerService.getById(id));
    }

    @UserRole({UserRoleEnum.student})
    @GetMapping
    public Result<?> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "10") Integer pageSize,
                              @RequestParam(defaultValue = "") String search) {
        return Result.success(sysQuestionAnswerService.findPage(pageNum, pageSize, search));
    }
}

